﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    matTomat
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <style type="text/css">
        input[type="text"], input[type="password"]
        {
            height: 40px;
            width: 90%;
            font-size: 25px;
        }
        .cell
        {
            line-height: 45px !important;
        }
        .col
        {
            font-weight: bolder;
            padding: 7px 0px 7px 100px !important;
            width: 20% !important;
            text-align: left !important;
            background-color: #ccc !important;
        }
        td.head
        {
            width: 20% !important;
            text-align: right !important;
            padding-right: 50px !important;
            border-left: 1px solid #000000;
            border-bottom: 1px solid #000000;
        }
        tr.head
        {
            border-left: 1px solid #000000 !important;
            border-right: 0px !important;
            line-height: 45px !important;
        }
        td.cell
        {
            border-right: 1px solid #000000;
        }
        .hide
        {
           display:none;
        }
    </style>
    <h2>
        MatTomat</h2>
    <table id="tblbarcode" width="80%">
        <tr class="rowa head">
            <td class="head cell" style="border: 1px solid #000000;">
                PLY BarCode
            </td>
            <td class="cell" style="border: 1px solid #000000; text-align: left;">
                <input id="barcode" type="password" onkeydown="checkEnter($(this));" />
            </td>
        </tr>
    </table>
    <br />
    <table style="width: 80%">
        <tr class="rowb">
            <td class="head " style="border-top: 1px solid #000000">
                Topped Cord
            </td>
            <td class="cell" id="code" style="border-top: 1px solid #000000">
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Topped Lot</td>
              <td class="cell" id="lot" style="border-top: 1px solid #000000">
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                PLY
            </td>
            <td class="cell" id="ply">
                <input type="text" id="txtply" /></td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Size
            </td>
            <td class="cell">
                <input type="text" id="txtsize" />
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Forming
                M/C</td>
            <td class="cell">
                <input type="text" id="txtforming" />
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Angle
            </td>
            <td class="cell">
                <input type="text" id="txtangle" />
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Width
            </td>
            <td class="cell">
                <input type="text" id="txtwidth" />
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Length
            </td>
            <td class="cell">
                <input type="text" id="txtlen" />
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Lot
                number</td>
            <td class="cell">
                <input type="text" id="txtlot" />
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Expired
                Date</td>
            <td class="cell">
                <input type="text" id="txtexp" />
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Rubber
                Sheet</td>
            <td class=" cell">
                <input type="checkbox" id="rubber" style="width: 35px; height: 35px;" /><input id="hdnrub" type="hidden" />
            </td>
        </tr>
        <tr class="rowb">
            <td class="head ">
                Tape
            </td>
            <td class="cell">
                <input type="checkbox" id="tape" style="width: 35px; height: 35px;" /><input id="hdntape" type="hidden" />
            </td>
        </tr>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="TableContent" runat="server">
    <div class="float-left" style="margin-left: 50px;">
        <input type="button" id="back" value="BACK" class="btnFooter" style="height: 75px;
            width: 350px;" />
    </div>
    <div style="float: right; margin-right: 35px;">
        <input id="print" type="button" value="Print" class="btnFooter hide" style="height: 75px;
            width: 350px;"  />
    </div>
    <div style="float: right; margin-right: 175px;">
        <input id="save" type="button" value="SAVE" class="btnFooter" style="height: 75px;
            width: 350px;" />
    </div>
    <input id="hdn" type="hidden" /><input id="side" type="hidden" />
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ScriptsSection" runat="server">
  <script src='<%: Url.Content("~/Scripts/autoNumeric.js") %>' type="text/javascript"></script>
  <script src='<%: Url.Content("~/Scripts/jquery.metadata.js") %>' type="text/javascript"></script>
    <% if (false)
       { %>
    <script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
    <% } %>
    <script type="text/javascript">
       function checkEnter(obj) {
           if (event.keyCode == 13) {
               var nm = (obj.attr("id"));
               $("#side").val("");
               $("#txtsize").focus();
               $("#print").addClass("hide");
           }
       }
       $(function () {
           $("#txtangle").attr("maxlength", 6).attr("mask", "999.99").autoNumeric({ vMin: '0', vMax: '999.99', aPad: false })
           $("#txtwidth").attr("maxlength", 6).attr("mask", "999.99").autoNumeric({ vMin: '0', vMax: '999.99', aPad: false })
           $("#txtlen").attr("maxlength", 6).attr("mask", "999.99").autoNumeric({ vMin: '0', vMax: '999.99', aPad: false })
           $("#txtlot").setMask("39/19-3").attr("maxlength", 7);

           $('#txtexp').dateEntry({ useMouseWheel: false, dateFormat: 'dmy/' });
           $("#barcode").focus().change(function () {
               Get_Detail();
           });

           $("#save").click(function () {
               Save_Data();
           });

           $("#back").click(function () {
               var nextURL = '<%= Url.Action("Index","BiasTail") %>';
               window.location = nextURL;
           });
           var detail;
           $("#print").click(function () {
               var arr = $("#hdn").val().split("-");
               var url = '<%=Url.Action("PRINT_PDF_MATTOMAT","PRINT_PDF")%>' + "?biasno=" + arr[3]
               url = url + "&plandt=" + arr[0] + "&itemno=" + arr[1] + "&sitemno=" + arr[2] + "&rollno=" + detail._rollno + "&side=" + $("#side").val();
               window.open(url);
           });

           function Save_Data() {
               if ($("#code").text() == "") {
                   alert("ระบุค่า Barcode");
                   $("#barcode").focus();
                   return;
               }
               if ($("#txtply").val() == "") {
                   alert("ระบุค่า Ply");
                   $("#txtply").focus();
                   return;
               }
               if ($("#txtsize").val() == "") {
                   alert("ระบุค่า Size");
                   $("#txtsize").focus();
                   return;
               }
               if ($("#txtforming").val() == "") {
                   alert("ระบุค่า Forming");
                   $("#txtforming").focus();
                   return;
               }
               if ($("#txtangle").val() == "") {
                   alert("ระบุค่า Angle");
                   $("#txtangle").focus();
                   return;
               }
               if ($("#txtwidth").val() == "") {
                   alert("ระบุค่า Width");
                   $("#txtwidth").focus();
                   return;
               }
               if ($("#txtlen").val() == "") {
                   alert("ระบุค่า Length");
                   return;
               }
               if ($("#txtexp").val() == "") {
                   alert("ระบุค่า Expire");
                   $("#txtexp").focus();
                   return;
               }
               if ($("#txtlot").val() == "") {
                   alert("ระบุค่า Lot");
                   $("#txtlot").focus();
                   return;
               }
               var sheet = "";
               var tape = "";

               if ($("#tape").is(':checked')) {
                   tape = "1";

               }
               if ($("#rubber").is(':checked')) {
                   sheet = "1";
               }


               var dataForSubmit = new Array();
               var arr = $("#hdn").val().split("-");
               dataForSubmit.push({
                   _biasno: arr[3],
                   _plandt: arr[0],
                   _itemno: arr[1],
                   _sitemno: arr[2],
                   _Newside: $("#txtply").val(),
                   _topcode: $("#code").text(),
                   _forming: $("#txtforming").val(),
                   _sizes: $("#txtsize").val(),
                   _angel: $("#txtangle").val(),
                   _toplen: $("#txtwidth").val(),
                   _plylen: $("#txtlen").val(),
                   _plyexp: $("#txtexp").val(),
                   _plylot: $("#txtlot").val() + "-" + $("#txtforming").val(),
                   _tapesheet: tape,
                   _topsheet: sheet,
                   _oldTape: detail._tapesheet,
                   _oldSheet: detail._topsheet,
                   _side: $("#side").val(),
                   _oldAngle: detail._angel,
                   _rollno: detail._rollno
               });
               var getUsersUrl = '<%= Url.Action("SAVE_MAT") %>';
               callScriptMethod(getUsersUrl, { theData: dataForSubmit }, 'ADD');
           }
           function callScriptMethod(url, jsonObject, action, callback, async) {

               callback = callback || function () { };
               async = (async == null || async);

               $.ajax({
                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: url,
                   data: JSON.stringify(jsonObject),
                   dataType: "json",
                   async: async,
                   success: function (data) {

                       if (data.success != "1") {
                           alert(data.message);
                       } else {
                           alert(data.message);
                           $("#print").removeClass("hide");
                           //                           $("#lot").text("");
                           //                           $("#code").text("");
                           //                           $("#txtforming").val("");
                           //                           $("#txtsize").val("");
                           //                           $("#txtangle").val("");
                           //                           $("#txtwidth").val("");
                           //                           $("#txtlen").val("");
                           //                           $("#txtexp").val("");
                           //                           $("#txtlot").val("");
                           //                           $("#txtply").val("");
                           //                           $("#tape").removeAttr('checked');
                           //                           $("#rubber").removeAttr('checked');
                           $("#barcode").focus();
                       }
                   },
                   error: function (xhr, status, error) {
                       var err = xhr.responseText;
                       alert(err.Message);
                   }
               });
           }

           function Get_Detail() {
               var barcode = $("#barcode").val();
               $("#barcode").val("");

               var arr = barcode.split("+");
               var url = '<%=Url.Action("Get_barcode")%>' + "?seq=" + arr[arr.length - 1] + "&rollno=" + arr[arr.length - 3] + "&ply=" + arr[1] + "&biasno=" + arr[arr.length - 2];

               $.post(url, function (data) {
                   if (data.length > 0) {
                       detail = data[0];
                       $("#txtply").val(data[0]._side);
                       $("#code").text(data[0]._topcode);
                       $("#lot").text(data[0]._topLot);
                       $("#txtforming").val(data[0]._forming);
                       $("#txtsize").val(data[0]._sizes);
                   
                       $("#txtangle").val(data[0]._angel);
                       $("#txtwidth").val(data[0]._Plymin);
                       $("#txtlen").val(data[0]._plylen);
                       $("#txtexp").val(data[0]._plyexp);
                       var lot = data[0]._plylot.split("-");
                       $("#txtlot").val(lot[0] + "-" + lot[1]);
                       $("#hdntape").val("");
                       $("#hdnrub").val("");

                       if (data[0]._tapesheet == "1") {
                           $("#tape").attr("checked", "checked");
                           $("#hdntape").val("1");
                       } else $("#tape").removeAttr("checked");
                       if (data[0]._topsheet == "1") {
                           $("#rubber").attr("checked", "checked");
                           $("#hdnrub").val("1");
                       } else $("#rubber").removeAttr("checked");
                       $("#hdn").val(arr[arr.length - 1] + '-' + data[0]._biasno);
                       $("#side").val(arr[1]);
                   }
               });
           }
       });
   
    </script>
</asp:Content>
